package cn.gzsf.springboot09.controller;

import cn.gzsf.springboot09.entity.Emp;
import cn.gzsf.springboot09.mapper.EmpMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmpController {
    @Autowired
    private EmpMapper empMapper;

    @RequestMapping("/add")
    public void add(Emp emp){
        empMapper.insert(emp);
    }

    @RequestMapping("/select")
    public List<Emp> select(){
        return empMapper.select();
    }

    @RequestMapping("/delete")
    public void delete(int id){
        empMapper.delete(id);
    }

    @RequestMapping("/selectOne")
    public Emp selectOne(int id){
        return empMapper.selectOne(id);
    }

    @RequestMapping("/update")  //如果前端直接传JS对象给后端，后端接收参数时需要添加@RequestBody
    public void update(@RequestBody Emp emp){
        empMapper.update(emp);
    }
}
